<template>
	<view>
		<tn-tabbar v-model="tabIndex" fixed>
			<tn-tabbar-item v-for="(item, index) in tabbarData" :key="index" :icon="item.icon"
				:active-icon="item.activeIcon" :text="item.name" @click="changePage(item.page)" :badge="item.badge"
				:badge-config="badgeConfig" />
		</tn-tabbar>
	</view>
</template>

<script lang="ts" setup>
	import socket from '@/util/websocket';
	import { ref } from 'vue';
	import { onShow } from "@dcloudio/uni-app";
	import type { AvatarBadgeProps } from '@tuniao/tnui-vue3-uniapp'
	import request from '@/util/request';
	import { tip } from '@/util/util';
	import type { RequestResponse } from '@/util/types';

	interface Props {
		index : number,
	}

	const props = defineProps<Props>()
	const tabIndex = ref<number>(-1)
	// 导航栏数据
	const tabbarData = ref<Array<any>>([
		{
			name: '首页',
			icon: 'home',
			activeIcon: 'home-fill',
			page: '/pages/index/index',
			badge: 0,
		},
		{
			name: '消息',
			icon: 'menu-circle',
			activeIcon: 'menu-circle-fill',
			page: '/pages/chat-list/chat-list',
			badge: 0,
		},
		{
			name: '我的',
			icon: 'my-circle',
			activeIcon: 'my-circle-fill',
			page: '/pages/user/user',
			badge: 0,
		},
	])

	uni.hideTabBar()
	onShow(() => {
		tabIndex.value = props.index
		// getUnread()
		// setInterval(function () {
		// 	tabbarData.value[1].badge = uni.getStorageSync('unread') || ''
		// }, 2000)
	})

	const badgeConfig : AvatarBadgeProps = {
		type: 'danger',
		size: 'lg',
		max: 99
	}

	const changePage = (page : string) => {
		uni.switchTab({
			url: page
		})
	}
</script>

<style>

</style>